﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<TireBias.Models.TailModel.TailBias_DS>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    INPUT_VALUE
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <table width="98%" >
<tr style="background-color:#20B2AA;color:White; height:50px; text-align:center"> <td style="width:300px">
ACTIVE PLAN :
</td>
<td  style="width:200px"><%= Model.First()._topcrdcd %></td> 
<td style="width:300px"><%= Model.First()._sizes %></td>
<td style="width:100px"><%= Model.First()._forming %></td>

<td style="text-align:left;" ><%= Model.First()._Text %></td>
</tr>
</table>

<table id="input" width="98%" class="shadow">
        <tr class="rowb">
            <td style="width: 320px;" class=" cell col btop ">
                PLY(1)
            </td>
            <td class="cell col btop">
                PLY Lot
            </td>
            <td colspan="2" class="cell btop brigth" id="lblot1">
               </td>
          <td style="width:320px;" class="cell btop">
                PLY(2)
            </td>
            <td class="cell btop">
                PLY Lot
            </td>
            <td colspan="2" class="cell btop col" id="lblot2">
                &nbsp;
            </td>
        </tr>
        <tr class="rowb">
            <td rowspan="3" class="cell col brigth">
         <div style="font-size: 6em; font-weight: bolder; line-height:115px"> <%= Model.First()._Ply1  %></div> 
            </td>
            <td class="cell col">
                Expired
            </td>
            <td colspan="2" class="cell brigth" id="lbexp1">
             
               
                  
            </td>
            <td rowspan="3" class="cell brigth">
                  <div style="font-size: 6em; font-weight: bolder; line-height:115px"> <%= Model.First()._Ply2 %></div> 
            </td>
            <td class="cell">
                Expired
            </td>
            <td colspan="2" class="cell col" id="lbexp2">
                &nbsp;
            </td>
        </tr>
        <tr class="rowb">
            <td class="cell col">
                Length M.
            </td>
            <td colspan="2" class="cell brigth">
                 <input type="text" id="txtlen1" style="width: 98%;" class="ply1" /></td>
            <td class="cell">
                Length M.
            </td>
            <td colspan="2" class="cell">
               <input type="text" id="txtlen2"  style=" width: 98%;" class="ply2"  />
            </td>
        </tr>
        <tr class="rowb">
            <td colspan="3" class="cell col brigth">
                Angle
            </td>
            <td colspan="3" class="cell brigth">
                Angle
            </td>
        </tr>
        <tr class="rowb">
            <td class="cell col brigth">Roll no.</td>
            <td class="col cell brigth"style="width:120px; ">
               <span  style="text-align:center; padding-left:45px;" >1</span>   </td>
            <td  style="width:120px;" class="cell col brigth">
             <span  style="text-align:center; padding-left:45px;" >2</span>  </td>
            <td  style="width:120px;" class="cell col brigth">
               <span  style="text-align:center; padding-left:45px;" >3</span>  </td>
            <td class="cell brigth">Roll no.</td>
            <td  style="width:120px;" class="cell brigth">
                 <span  style="text-align:center; padding-left:45px;" >1</span> </td>
            <td  style="width:120px;" class="cell brigth">
                  <span  style="text-align:center; padding-left:45px;" >2</span> 
            </td>
            <td  style="width:120px;" class="cell brigth">
                   <span  style="text-align:center; padding-left:45px;" >3</span> </td>
        </tr>
        <tr class="rowb">
            <td rowspan="3" class="cell col brigth">
              <div id="rollno1" style="text-align: center; font-size: 8em;
               font-weight: bolder; width: 98%; line-height: 98%">
             </div></td>
            <td class="cell col">
                 <input type="text" id="roll1" class="ply1 txt-float" /></td>
            <td class="cell col">
                 <input type="text" id="roll2" class="ply1 txt-float" disabled="disabled"  /></td>
            <td class="cell col">
                 <input type="text" id="roll3" class="ply1 txt-float" disabled="disabled" /></td>
            <td rowspan="3" class="cell brigth"> 
                <div id="rollno2" style="text-align: center; font-size: 8em;
               font-weight: bolder; width: 98%; line-height: 98%">
             </div></td>
               <td class="cell">
                 <input type="text" id="roll21" class="ply2 txt-float" /></td>
             <td class="cell">
                 <input type="text" id="roll22" class="ply2 txt-float" disabled="disabled" /></td>
             <td class="cell">
                 <input type="text" id="roll23" class="ply2 txt-float" disabled="disabled" /></td>
        </tr>
        <tr class="rowb">
            <td class="cell col brigth" colspan="3">
                Width (mm.)</td>
            <td class="cell brigth" colspan="3">
                Width (mm.)</td>
        </tr>
        <tr class="rowb">
            <td class="cell col brigth">
                1</td>
            <td class="cell col brigth">
                2</td>
            <td class="cell col brigth">
                3</td>
            <td class="cell brigth">
                1</td>
            <td class="cell brigth">
                2</td>
            <td class="cell brigth">
                3</td>
        </tr>
        <tr class="rowb">
            <td class="cell col brigth">Cart no.</td>
                <td class="cell">
                <input type="text" id="cart1" class="ply1" /></td>
                <td class="cell">
                <input type="text" id="cart2" class="ply1" disabled="disabled" /></td>
                <td class="cell">
                <input type="text" id="cart3" class="ply1" disabled="disabled" /></td>
            <td class="cell">Cart no.</td>
                    <td class="cell">
                <input type="text" id="cart21" class="ply2" /></td>
                <td class="cell">
                <input type="text" id="cart22" class="ply2" disabled="disabled" /></td>
                 <td class="cell">
                <input type="text" id="cart23" class="ply2" disabled="disabled" /></td>
        </tr>
        <tr class="rowb">
            <td rowspan="5" class="cell ">
                <input type="text" id="cartno1" 
                    style="height:187px; font-size:120px; text-align:center; width: 98%;" 
                    class="ply1" /></td>
            <td colspan="3" class="cell col brigth">
                join</td>
            <td rowspan="5" class="cell">
                <input type="text" id="cartno21" 
                    style="height:187px; font-size:120px; text-align:center; width: 98%;" 
                    class="ply2" /></td>
            <td colspan="3" class="cell brigth">
                join</td>
        </tr>
        <tr class="rowb">
            <td class="cell col brigth">
                1</td>
            <td class="cell col brigth">
                2</td>
            <td class="cell col brigth">
                3</td>
            <td class="cell brigth">
                1</td>
            <td class="cell brigth">
                2</td>
            <td class="cell brigth">
                3</td>
        </tr>
        <tr class="rowb">
            <td class="cell">
                <input type="text" id="join1" class="ply1" /></td>
                <td class="cell">
                <input type="text" id="join2" class="ply1" disabled="disabled" /></td>
                <td class="cell">
                <input type="text" id="join3" class="ply1" disabled="disabled" /></td>
          <td>
                <input type="text" id="join21" class="ply2" /></td>
                <td>
                <input type="text" id="join22" class="ply2" disabled="disabled" /></td>
                <td>
                <input type="text" id="join23" class="ply2" disabled="disabled" /></td>
        </tr>
        <tr class="rowb">
            <td class="cell">
                <img class="style1" src="<%: Url.Content("~/Images/check-icon.png")%>" id="imgchk1" /></td>
             
                <td class="cell">
                  <img class="style1" src="<%: Url.Content("~/Images/check-icon.png")%>" id="imgchk2" /></td>
                 <td  class="cell">
                  <img class="style1" src="<%= Url.Content("~/Images/check-icon.png")%>"id="imgchk3"   /></td>
                   <td  class="cell">
                  <img class="style1"src="<%= Url.Content("~/Images/check-icon.png")%>" id="imgchk21"   /></td>
                   <td  class="cell">
                  <img class="style1" src="<%= Url.Content("~/Images/check-icon.png")%>" id="imgchk22"   /></td>
                   <td  class="cell">
                  <img class="style1" src="<%= Url.Content("~/Images/check-icon.png")%>" id="imgchk23"   /></td>
             
        </tr>
        </table>

<%     var second = new TireBias.Models.TailModel.TailBias_DS();

    if (Model.Count() > 1)
    {
        second = Model.ElementAt(1);
        
    }
    if (WinNemoLib.StrUtil.IsNotEmpty(second._plandt))
         {%>
   <table width="98%" class="shadow">
     <tr class="rowa" style="background-color:#FFDF80">
         <td class="cell head" style="font-size: x-large;line-height: 30px; 
            padding: 5px; background-color: #C38DEC;" colspan="3">
            NEXT PLAN
         </td>
         <td class="cell head">
         <%= second._topcrdcd %>
         </td>
           <td class="cell head">
         <%= second._sizes %>
         </td>
        <td class="cell head">
         <%= second._forming %>
         </td>
         <%  if ((second._Ply1 == "P1") || (second._Ply2 == "P1"))
            { %>
        <td class="cell head">P1</td>
         <% } %>
            <%  if ((second._Ply1 == "P2") || (second._Ply2 == "P2"))
            { %>
           <td class="cell head">P2</td>
            <% } %>
         <% if  ((second._Ply1 == "P3") || (second._Ply2 == "P3"))
            { %>
          <td class="cell head">P3</td>
         <% } %>
                <%  if ((second._Ply1 == "P4") || (second._Ply2 == "P4"))
            { %>
          <td class="cell head">P4</td>
         <% } %>
      </tr></table>
      <%} %>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <div id="numericInput" style="float:left; width:300px;" >   
   <table id="keypad" class="hide">
         <tr style="background-color:#696969;"><td colspan="3" style="text-decoration:none; text-align:right;">
         <img src="<%: Url.Content("~/Images/power.png")%> "  alt='' width="100px" height="75px" id="close" />
         </td></tr>
         <tr class="rowa" >
            <td class="key">
               1
            </td>
            <td class="key ">
               2
            </td>
            <td class="key ">
               3
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key ">
               4
            </td>
            <td class="key ">
               5
            </td>
            <td class="key ">
               6
            </td>
         </tr>
         <tr class="rowa" >
            <td class="key ">
               7
            </td>
            <td class="key ">
               8
            </td>
            <td class="key ">
               9
            </td>
         </tr>
         <tr class="rowa" >
            <td class="btn">
               DEL
            </td>
            <td class="key ">
               0
            </td>
            <td class="key ">
               .
            </td>
         </tr>
      </table>
</div>

</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="TableContent" runat="server">
    <div style="clear: left; margin-top: 15px; ">
      <div class="float-left" style="margin-left: 10px">
        <input id="back" type="button" value="BACK"class="btnFooter shadow" style="height: 75px; width: 120px;" />
      </div> 
       <div class="float-left" style="margin-left: 10px">
        <input id="head" type="button" value="PLAN" class="btnFooter shadow" style="height: 75px; width: 120px;" />
        </div>
           <div class="float-left" style="margin-left: 5px;">
         <input id="save" type="button" value="SAVE"class="btnFooter shadow" style="height: 75px; width: 120px; display:none;" />
      </div>
          <div class="float-left" style="margin-left: 5px;">
         <input type="button" id="print1" value="PRINT PLY(1)"class="btnFooter shadow "   style="height: 75px;  width: 120px;" />
      
      </div>
     <div class="float-left" style="margin-left: 70px; ">
       <input id="wast" type="button" value="WASTE" class="btnFooter shadow" 
             style="height: 75px; width: 117px; " />
     <%--    <input type="button" id="new1" value="NEW ROLL(1)"class="btnFooter shadow"   style="height: 75px;"   />--%>
        <input id="report" type="button" value="REPORT" class="btnFooter shadow" 
             style="border-style: 1; height: 75px; width: 120px; background-color: #0099FF; color: #FFFFFF;" />
       <input id="loss" type="button" value="LOSS" class="btnFooter shadow" 
             style="height: 75px; width: 117px; " /></div>
     <div class="float-left" style="margin-left: 210px;">
         <input type="button" id="print2" value="PRINT PLY(2)"class="btnFooter shadow "   style="height: 75px; width: 120px;" />
      </div>
      <div  class="float-right " style="margin-right:10px; display:none;">       
                  <input type="button" id="new2" value="NEW ROLL(2)"class="btnFooter shadow "   style="height: 75px;" />
      </div>
  
   </div>  
   <input type="hidden" id="prddate" />
<div id="timer" style="margin-left:12%"  title="กรุณารอสักครู่...">
<div id="counter_2" style="height: 77px; overflow: hidden;" >
</div>
</div>



<div id="dialog-plan">
      <table class=" shadow fontTB "id="dataTbl" width="98%">
         <thead>
            <tr class="head">
               <td class="cell" style="width: 17%; " rowspan="2">
                  SEQ<br /><span class="fontTh">ลำดับ</span>
               </td>
               <td class="cell" style="width: 20%" rowspan="2">
                  TOPPED CORD<br /><span class="fontTh">ผ้าใบ</span>
               </td>
               <td class="cell" style="width: 15%" rowspan="2">
                  SIZE<br /><span class="fontTh">ขนาดผ้าใบ</span>
               </td>
               <td class="cell" colspan="4" align="center" style="border-bottom:1px solid #000000">
               <span class="fontTh">  ความยาวผ้าใบ</span> <span class="fontTh">(มม.)</span></td>
               <td class="cell" style="width: 15%; " rowspan="2">
                  FORMING<br /><span class="fontTh">ขนาดผ้าใบ</span>
               </td>
                 <td class="cell" style=" " rowspan="2">
                  TEXT<br /><span class="fontTh">ข้อความ</span>
               </td>
            </tr>
            <tr class="head">
               <td class="cell" style="width: 10%;">
                  P1<br /><span class="fontTh">ชั้นที่ 1 </span>&nbsp;</td>
                 <td class="cell" style="width: 10%;">
                  P2<br /><span class="fontTh">ชั้นที่ 2 </span>&nbsp;</td>
                 <td class="cell" style="width: 10%;">
                  P3<br /><span class="fontTh">ชั้นที่ 3</span>
               </td>
                 <td class="cell" style="width: 10%;">
                  P4<br /><span class="fontTh">ชั้นที่ 4 </span>
               </td>
            </tr>
            <tr id="trHd" class="hide">
            <td class="cell" >&nbsp;</td>
            <td class="cell" >&nbsp;</td>
            <td class="cell" >&nbsp;</td>
               <td class="cell" style="width: 10%;">               
                  P1</td>
                 <td class="cell" style="width: 10%;">
                  P2</td>
                 <td class="cell" style="width: 10%;">
                  P3
               </td>
                 <td class="cell" style="width: 10%;">
                  P4
               </td>
               <td class="cell" >&nbsp;</td>   
               <td class="cell" >&nbsp;</td>
            </tr>
            
         </thead>
         <tbody></tbody>
         
      </table>
      </div>
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="ScriptsSection" runat="server">

    <script src='<%: Url.Content("~/Scripts/autoNumeric.js") %>' type="text/javascript"></script>
    <script src='<%: Url.Content("~/Scripts/jquery.metadata.js") %>' type="text/javascript"></script>
<style type="text/css">
 br { clear: both; }
.cntSeparator {
    font-size: 54px;
    margin: 10px 7px;
    color: #000;
}
.desc { margin: 7px 3px; }
.desc div {
    float: left;
    font-family: Arial;
    width: 70px;
    margin-right: 65px;
    font-size: 13px;
    font-weight: bold;
    color: #000;
}
    
#new1,#new2
{
    background-color:Red;
    color:Black;
    width:120px;
}
#new1:hover,#new2:hover
{   
    color:White;   
}
#save
{
    width:150px;
}
.actived
{
background-color:#008080; 
color:White; 
    /*red*/               
}    
.key
{
    border:1px solid #000000 !important;
}
#close:hover
{
    cursor:pointer;
}
#input .cell
{
 line-height:50px !important;
 font-weight:bolder;

 padding:0px !important;  text-align:center;
}
.col
{ 

  background-color:#D9D9D9 !important;

}
.hide
{
    display:none;
}
input[type="text"]
{
    height: 43px;
    width: 96%;
    font-size: 30px;
    background-color: #DBEEF4;
    border: 2px solid #ffffff;
    text-align:right;
    
}
.btop
{
    border-top:1px solid black !important;
}
.brigth
{
    border-right:1px solid black !important;
}
.style1
{
    width: 46px;
    height: 46px;
    cursor:hand;
    text-align:center;
}
.text-center
{
    text-align:center;
}
.hide
{
    display:none;
}
.actived
{
    background-color: #20B2AA !important;
    color: White;
}
input[disabled]
{
background-color:#F0F0F0 !important; 
color:#000000 !important;
}
</style>
<% if (false)
   { %>
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<% } %>

<script type="text/javascript">

    $(function () {

        $("#report").click(function () {

            var url = '<%=Url.Action("Report","DemoReport") %>' + "?code=" + '<%= Model.First()._biasno %>';
            url += "&topcode=" + '<%: Model.First()._topcrdcd %>' + "&toplot=" + '<%: Model.First()._toplot  %>' + "&rep=a2";
            url += "&roll=" + '<%: Model.First()._toproll %>';
            window.open(url)
        });

        $("#timer").dialog({
            width: 350,
            modal: true,
            closeOnEscape: false,
            position: {
                my: 'center',
                at: 'center'
            },
            autoOpen: false,
            show: "blind",
            open: function (event, ui) {
                $(".ui-dialog-titlebar-close").hide();
                $('#counter_2').empty();
                $('#counter_2').removeClass("hide").countdown({
                    stepTime: 60,
                    image: '<%:Url.Content("~/images/digits.png")%>',
                    startTime: '01:00',
                    timerEnd: function () { $("#timer").dialog("close"); $('#counter_2').empty(); },
                    format: 'mm:ss'
                })
            }
        });

        $("#dialog-plan").dialog({
            width: 1200,
            height: 600,
            position: {
                my: 'center',
                at: 'center'
            },
            autoOpen: false,
            show: "blind",
            open: function (event, ui) {
                $.post('<%=Url.Action("Header_line","BiasTail") %>' + '?biasno=' + '<%: Model.First()._biasno %>'
                    , function (data) {
                        $("#dataTbl tbody").empty();
                        for (i = 0; i < data.length; i++) {
                            var seq = data[i]._Plandt + '-' + data[i]._Itemno;
                            var row = "rowb";
                            if (i % 2 == 0) {
                                row = "rowa";
                            }
                            var $tr = $("#trHd").clone();
                            $tr.removeClass("hide").addClass(row);
                            if (i == 0) {
                                $tr.addClass("actived");
                            }
                            $("td:eq(0)", $tr).text(seq).addClass("text-center");
                            $("td:eq(1)", $tr).text(data[i]._Topcrdcd);
                            $("td:eq(2)", $tr).text(data[i]._Size);
                            $("td:eq(3)", $tr).text(data[i]._P1).addClass("text-center");
                            $("td:eq(4)", $tr).text(data[i]._P2).addClass("text-center");
                            $("td:eq(5)", $tr).text(data[i]._P3).addClass("text-center");
                            $("td:eq(6)", $tr).text(data[i]._P4).addClass("text-center");
                            $("td:eq(7)", $tr).text(data[i]._Forming).addClass("text-center");
                            $("td:eq(8)", $tr).text(data[i]._Text);
                            $tr.appendTo($("#dataTbl tbody"));
                        }
                    }); //post
            }
        });

        $("#head").click(function () {
            $("#dialog-plan").dialog("open");
        });
        $("#wast").click(function () {
            var nextURL = '<%= Url.Action("AddWaste","BIASWASTE") %>';
            nextURL += '?returnUrl=' + '<%= Url.Action("Input_value","biasTail") %>' + '?dtplan=' + '<%= Model.First()._plandt %>' + '|itemno=' + '<%= Model.First()._itemno %>' + '|sitemno=' + '<%= Model.First()._sitemno %>';
            nextURL += '&biasno=' + '<%= Model.First()._biasno %>'
            nextURL += '&tirecode=' + '<%= Model.First()._topcrdcd %>'
            nextURL += '&toplot=' + '<%= Model.First()._toplot %>'
            nextURL += "&toproll=" + '<%: Model.First()._toproll %>'
            window.location = nextURL;
        });
        $("#loss").click(function () {
            var nextURL = '<%= Url.Action("index","BiasLoss") %>';
            nextURL += '?returnUrl=' + '<%= Url.Action("Input_value","biasTail") %>' + '?dtplan=' + '<%= Model.First()._plandt %>' + '|itemno=' + '<%= Model.First()._itemno %>' + '|sitemno=' + '<%= Model.First()._sitemno %>';
            nextURL += '&biasno=' + '<%= Model.First()._biasno %>'
            nextURL += '&tirecode=' + '<%= Model.First()._topcrdcd %>'
            nextURL += '&toplot=' + '<%= Model.First()._toplot %>'
            nextURL += "&toproll=" + '<%: Model.First()._toproll %>'
            window.location = nextURL;
        });
        var ply1 = '<%= Model.First()._Ply1 %>';
        var ply2 = '<%= Model.First()._Ply2 %>';
        var dtpln = '<%= Model.First()._plandt %>';
        var item = '<%= Model.First()._itemno %>';
        var sitem = '<% =Model.First()._sitemno %>';

        var shift = 1;
        var btnClick = null;

        $(".style1").click(function () {
            btnClick = $(this);
            var bln = false;
            var no = "";
            switch ($(this).attr("id")) {
                case "imgchk1": no = 1; break;
                case "imgchk2": no = 2; break;
                case "imgchk3": no = 3; break;
                case "imgchk21": no = 4; break;
                case "imgchk22": no = 5; break;
                case "imgchk23": no = 6; break;
            }

            if (no == "") return;

            bln = valid_angle_width(no);

            if (bln == true) {

                if ((no != 3) && (no != 6) && ('<%= Model.First()._Delay %>' == 'true')) {
                    $("#timer").dialog("open");
                }

                Save_data($(this), no);
            }
        });

        $("#new1").click(function () {
            btnClick = $(this);
            var blnR = 'true';
            blnR = validate_data(1);

            if (blnR == 'true') {
                $("#rollno1").text(parseInt($("#rollno1").text()) + 1);
                $("#cartno1").val("");
                $("#txtlen1").val("");
                $("#roll1").val("").removeAttr("disabled");
                $("#roll2").val("");
                $("#roll3").val("");
                $("#cart1").val("").removeAttr("disabled");
                $("#cart2").val("");
                $("#cart3").val("");
                $("#join1").val("").removeAttr("disabled");
                $("#join2").val("");
                $("#join3").val("");
                $("#imgchk1").removeClass("hide");
            }
        });

        $("#back").click(function () {
            window.location = '<%= Url.Action("GET_STD")%>';
        });

        $("#new2").click(function () {
            btnClick = $(this);
            var blnR = 'true';
            blnR = validate_data(2);

            if (blnR == 'true') {
                $("#rollno2").text(parseInt($("#rollno2").text()) + 1);
                $("#cartno21").val("");
                $("#txtlen2").val("");
                $("#roll21").val("").removeAttr("disabled"); ;
                $("#roll22").val("");
                $("#roll23").val("");
                $("#cart21").val("").removeAttr("disabled"); ;
                $("#cart22").val("");
                $("#cart23").val("");
                $("#join21").val("").removeAttr("disabled"); ;
                $("#join22").val("");
                $("#join23").val("");
                $("#imgchk21").removeClass("hide");
            }
        });
        $("#numericInput").draggable();

        function DisableText(txt) {
            $(txt).attr("disabled", "disabled");
        }
        function DisplayTxt(txt) {
            $(txt).removeAttr("disabled");
        }


        function valid_angle_width(no) {
            var ang;
            var width;
            var join;
            var ang1 = "";
            var width1 = "";
            var join1 = "";

            switch (no) {
                case 1:
                    ang = "#roll1";
                    width = "#cart1";
                    join = "#join1"
                    break;
                case 2:
                    ang = "#roll2";
                    width = "#cart2";
                    join = "#join2"
                    break;

                case 3:
                    ang = "#roll3";
                    width = "#cart3";
                    join = "#join3"
                    break;
                case 4:
                    ang = "#roll1";
                    width = "#cart1";
                    join = "#join1"
                    ang1 = "#roll21";
                    width1 = "#cart21";
                    join1 = "#join21"
                    break;
                case 5:
                    ang = "#roll2";
                    width = "#cart2";
                    join = "#join2"
                    ang1 = "#roll22";
                    width1 = "#cart22";
                    join1 = "#join22"
                    break;

                case 6:
                    ang = "#roll3";
                    width = "#cart3";
                    join = "#join3"
                    ang1 = "#roll23";
                    width1 = "#cart23";
                    join1 = "#join23"
                    break;

            }

            if (ang == "") {
                return false;
            }

            if (!check_angle(ang)) {
                return false;
            }


            if (!check_width(width)) {
                return false;
            }


            if ($(join).val() == "") {
                alert("ระบุค่าไม่ครบ");
                clickNum = $(join);
                $(join).focus();
                return false;
            }


            if (ang1 != "") {

                if (!check_angle(ang1)) {
                    return false;
                }
            }

            if (width1 != "") {
                if (!check_width(width1)) {
                    return false;
                }

            }

            if (join1 != "") {
                if ($(join1).val() == "") {
                    alert("ระบุค่าไม่ครบ");
                    clickNum = $(join1);
                    $(join1).focus();
                    return false;
                }

            }
            CheckText(no);
            return true;


        }

        function GET_DATA(ply, side) {

            var urlGET = '<%= Url.Action("GET_FORINPUT")%>';
            urlGET = urlGET + '?dtPlan=' + dtpln + '&itemno=' + item + '&sitemno=' + sitem + '&side=' + side;

            $.post(urlGET, function (data) {

                if (data.length > 0) {

                    if (side == "L") {
                        $("#prddate").val(data[0]._prddate);
                        $("#rollno1").text(data[0]._rollno);
                        $("#cartno1").val(data[0]._cartno);
                        $("#lblot1").text(data[0]._plylot);
                        $("#lbexp1").text(data[0]._plyexp);
                        $("#txtlen1").val(data[0]._plylen);
                        $("#roll1").val(data[0]._Plyan1);
                        $("#roll2").val(data[0]._Plyan2);
                        $("#roll3").val(data[0]._Plyan3);
                        $("#cart1").val(data[0]._Plywd1);
                        $("#cart2").val(data[0]._Plywd2);
                        $("#cart3").val(data[0]._Plywd3);
                        $("#join1").val(data[0]._Plyjn1);
                        $("#join2").val(data[0]._Plyjn2);
                        $("#join3").val(data[0]._Plyjn3);
                    }

                    if (side == "R") {
                        $("#prddate").val(data[0]._prddate);
                        $("#rollno2").text(data[0]._rollno);
                        $("#cartno21").val(data[0]._cartno);
                        $("#lblot2").text(data[0]._plylot);
                        $("#lbexp2").text(data[0]._plyexp);
                        $("#txtlen2").val(data[0]._plylen);
                        $("#roll21").val(data[0]._Plyan1);
                        $("#roll22").val(data[0]._Plyan2);
                        $("#roll23").val(data[0]._Plyan3);
                        $("#cart21").val(data[0]._Plywd1);
                        $("#cart22").val(data[0]._Plywd2);
                        $("#cart23").val(data[0]._Plywd3);
                        $("#join21").val(data[0]._Plyjn1);
                        $("#join22").val(data[0]._Plyjn2);
                        $("#join23").val(data[0]._Plyjn3);
                    }
                    CheckText();
                }
                else {
                    var getexp = '<%= Url.Action("GET_EXP")%>';
                    getexp = getexp + '?sizes=' + '<%= Model.First()._sizes %>' + '&topcode=' + '<%= Model.First()._topcrdcd %>' + '&forming=' + '<%= Model.First()._forming %>' + '&dtPlan=' + dtpln;
                    $.post(getexp, function (data) {
                        var exp = data.exp;
                        var sDate = data.dCur;
                        var mon = data.mCur;
                        if (mon <= 9) mon = '0' + mon;
                        if (sDate <= 9) sDate = '0' + sDate;
                        var lot = sDate + '/' + mon + '-' + data.shift + '-' + '<%= Model.First()._forming %>';

                        $("#prddate").val(data.cur);
                        if (side == "L") {
                            $("#lblot1").text(lot)
                            $("#lbexp1").text(exp);
                            $("#rollno1").text(1);
                        }
                        if (side == "R") {
                            $("#lblot2").text(lot)
                            $("#lbexp2").text(exp);
                            $("#rollno2").text(1);
                        }
                    });

                }
            });
        }

        var data

        if (typeof (ply1) != undefined) {
            data = GET_DATA(ply1, 'L');

            CheckText();
        }

        if ((typeof (ply2) != undefined) && $.trim(ply2) != '') {

            data = GET_DATA(ply2, 'R');
        } else {
            $(".ply2,#print2,#new2").addClass("hide");

        }

        /// KEY PAD /////

        var clickNum = null;
        $('.key').click(function (event) {

            var numBox = clickNum;
            if (clickNum.is(':disabled')) {
                return;
            }
            var marks = (numBox).attr("mask");
            var max = (numBox).attr("maxlength").length;
            var maskArray = marks.split('');
            if (numBox.val().length == max) {
                return;
            }

            var v = $.trim(this.innerHTML);
            var valueArray = ($.trim(numBox.val())).split('')
            var idx = $.inArray(".", valueArray);

            if ((v == ".") && (idx > -1)) {
                return;
            }

            if ($.trim(this.innerHTML) == ".") {
                if ($.inArray(".", maskArray) < 0) {
                    return;
                }
                numBox.val(numBox.val() + '.');
                return;
            }

            var i = valueArray.length;


            if (idx >= 0) {
                var pt = maskArray.length - ($.inArray(".", maskArray));
                var x = valueArray.length + 1 - idx;
                if (x > pt) {
                    return;
                }
                i = $.inArray(".", maskArray) + 1;


            } else if ((i > 0) && (maskArray[i] == '.')) {
                numBox.val(numBox.val() + '.');
            }

            if (maskArray[i] == 'undefine') {
                return;
            }

            if (v <= maskArray[i]) {
                numBox.val(numBox.val() + v);
            }

            event.stopPropagation();
        });


        $('.btn,#close').click(function (event) {
            var numBox = clickNum
            if ($.trim(this.innerHTML) == 'DEL') {
                if (numBox.val().length > 0) {

                    clickNum.val(numBox.val().substring(0, numBox.val().length - 1));
                }
                else {
                    numBox.val('');
                }
            }
            else {
                $("#keypad").slideToggle();
                clickNum = null;
            }
            //    CheckText();
            event.stopPropagation();
        });


        //$("input:text").addClass("request");

        $('input:text:not(.txt-float)').attr("mask", "999").attr("maxlength", 3).click(function (event) {
            var parentOffset = $(this).offset();
            var o = {
                left: event.pageX - parentOffset.left + 100,
                top: event.pageY - parentOffset.top + 150
            };

            if ((clickNum == null) || ($(this).attr("id") == clickNum.attr("id"))) $("#keypad").slideToggle().offset(o);
            clickNum = $(this);
            event.stopPropagation();
        });

        $('.txt-float').attr("maxlength", 6).attr("mask", "999.99").click(function (event) {
            var parentOffset = $(this).offset();
            var o = {
                left: event.pageX - parentOffset.left + 50,
                top: event.pageY - parentOffset.top + 150
            };

            if ((clickNum == null) || ($(this).attr("id") == clickNum.attr("id"))) $("#keypad").slideToggle().offset(o);
            clickNum = $(this);
            event.stopPropagation();
        });

        $('.txt-float').autoNumeric({ vMin: '0', vMax: '999.99', aPad: false });
        $('input:text:not(.txt-float)').autoNumeric({ vMin: '0', vMax: '999', aPad: false });

        $("#save").click(function () {
            btnClick = $(this);
            var res = true;
            if (!($("#roll1").is(":disabled"))) {
                if ($("#roll1").val() != "") {
                    res = check_angle("#roll1");
                    if (!res) return;
                }
                if ($("#cart1").val() != "") {
                    res = check_width("#cart1");
                    if (!res) return;
                }
            }

            if (!($("#roll2").is(":disabled"))) {
                if ($("#roll2").val() != "") {
                    res = check_angle("#roll2");
                    if (!res) return;
                }
                if ($("#cart2").val() != "") {
                    res = check_width("#cart2");
                    if (!res) return;
                }
            }

            if (!($("#roll3").is(":disabled"))) {
                if ($("#roll3").val() != "") {
                    res = check_angle("#roll3");
                    if (!res) return;
                }
                if ($("#cart3").val() != "") {
                    res = check_width("#cart3");
                    if (!res) return;
                }
            }
            if ((typeof (ply2) != undefined) && $.trim(ply2) != '') {
                if (!($("#roll21").is(":disabled"))) {
                    if ($("#roll21").val() != "") {
                        res = check_angle("#roll21");
                        if (!res) return;
                    }
                    if ($("#cart21").val() != "") {
                        res = check_width("#cart21");
                        if (!res) return;
                    }
                }
                if (!($("#roll22").is(":disabled"))) {
                    if ($("#roll22").val() != "") {
                        res = check_angle("#roll22");
                        if (!res) return;
                    }
                    if ($("#cart22").val() != "") {
                        res = check_width("#cart22");
                        if (!res) return;
                    }
                }

                if (!($("#roll23").is(":disabled"))) {
                    if ($("#roll23").val() != "") {
                        res = check_angle("#roll23");
                        if (!res) return;
                    }
                    if ($("#cart23").val() != "") {
                        res = check_width("#cart23");
                        if (!res) return;
                    }
                }
            }
            if (res) {
                Save_data($("#save"));
            }

        });

        $("#print1").click(function () {
            btnClick = $(this);
            var res = validate_data(1);

            if (res == 'true') {
                if (!($("#roll1").is(":disabled"))) {
                    if ($("#roll1").val() != "") {
                        res = check_angle("#roll1");
                        if (!res) return;
                    }
                    if ($("#cart1").val() != "") {
                        res = check_width("#cart1");
                        if (!res) return;
                    }
                }

                if (!($("#roll2").is(":disabled"))) {
                    if ($("#roll2").val() != "") {
                        res = check_angle("#roll2");
                        if (!res) return;
                    }
                    if ($("#cart2").val() != "") {
                        res = check_width("#cart2");
                        if (!res) return;
                    }
                }

                if (!($("#roll3").is(":disabled"))) {
                    if ($("#roll3").val() != "") {
                        res = check_angle("#roll3");
                        if (!res) return;
                    }
                    if ($("#cart3").val() != "") {
                        res = check_width("#cart3");
                        if (!res) return;
                    }
                }
            }


            if (res == 'true') {
                Save_data($(this))

                var url = '<%=Url.Action("PRINT_PDF_BARCODE","PRINT_PDF")%>' + "?biasno=" + '<%= Model.First()._biasno %>'
                url = url + "&plandt=" + dtpln + "&itemno=" + item + "&sitemno=" + sitem + "&side=" + "L" + "&rows=" + $("#rollno1").text();
                document.body.style.cursor = "wait";
                CheckText();
                setTimeout(function () { window.open(url); document.body.style.cursor = "default"; }, 1000);
            }

        });
        $("#print2").click(function () {
            btnClick = $(this);
            var res = validate_data(2);
            if (res == 'true') {
                if (!($("#roll21").is(":disabled"))) {
                    if ($("#roll21").val() != "") {
                        res = check_angle("#roll21");
                        if (!res) return;
                    }
                    if ($("#cart21").val() != "") {
                        res = check_width("#cart21");
                        if (!res) return;
                    }
                }
                if (!($("#roll22").is(":disabled"))) {
                    if ($("#roll22").val() != "") {
                        res = check_angle("#roll22");
                        if (!res) return;
                    }
                    if ($("#cart22").val() != "") {
                        res = check_width("#cart22");
                        if (!res) return;
                    }
                }

                if (!($("#roll23").is(":disabled"))) {
                    if ($("#roll23").val() != "") {
                        res = check_angle("#roll23");
                        if (!res) return;
                    }
                    if ($("#cart23").val() != "") {
                        res = check_width("#cart23");
                        if (!res) return;
                    }
                }
            }

            if (res == 'true') {
                Save_data($(this))
                var url = '<%=Url.Action("PRINT_PDF_BARCODE","PRINT_PDF")%>' + "?biasno=" + '<%= Model.First()._biasno %>'
                url = url + "&plandt=" + dtpln + "&itemno=" + item + "&sitemno=" + sitem + "&side=" + "R" + "&rows=" + $("#rollno2").text();
                CheckText();
                setTimeout(function () { window.open(url); document.body.style.cursor = "default"; }, 1000);
            }

        });

        Number.prototype.between = function (first, last) {
            return (first < last ? this >= first && this <= last : this >= last && this <= first);
        }



        function validate_data(opt) {
            var blnR = 'true';
            var blnFc = 'false';
            $(".ply" + opt + ":not(.hide)").each(function () {
                $(this).parent().find("font").empty();
                if ($(this).val() == '') {
                    if (blnFc == 'false') {
                        blnR = 'false';
                        if ($(this).is(":disabled")) {

                        } else {

                            blnFc = 'true';
                            $(this).focus();
                            $(this).parent().append("<font color='red'>*</font>");
                            alert('ระบุค่าไม่ครบ');
                        }
                    }

                    if (blnFc == 'true') return blnR;
                }
            });

            if ((blnFc == 'false') && (blnR == 'false')) alert("ระบุค่าไม่ครบ");

            return blnR;
        }

        function check_angle(nm) {
            var obj = $(nm);

            var a = parseFloat('<%= Model.First()._Angle  %>');

            var roll = parseFloat(obj.val());
            if (!roll.between(a - 1, a + 1)) {
                alert("Angle under and over standard (องศาไม่ถูกต้อง).");
                clickNum = obj;
                obj.focus();
                return false;
            }
            return true;
        }

        function check_width(nm) {
            var obj = $(nm);


            var w = '<%= Model.First()._Width  %>';
            var w2 = '<%= Model.First()._Width2  %>';
            var a = parseInt(w);
            if (obj.hasClass('ply2')) {
                a = parseInt(w2);
            }
            var roll = parseInt(obj.val());
            if (!roll.between(a - 5, a + 5)) {
                alert("Width under and over standard (ความกว้างไม่ถูกต้อง).");
                clickNum = obj;
                obj.focus();
                return false;
            }
            return true;
        }

        function Save_data(obj, no) {
            var blnR = 'true';
            var nm = (obj.attr("id"));

            var dataForSubmit = new Array();
            if (blnR == 'true') {
                if (typeof (no) == 'undefined') {
                    no = 0;
                }
                if (no.between(0, 6)) {
                    dataForSubmit.push({
                        _biasno: '<%= Model.First()._biasno %>',
                        _shift: '<%= Model.First()._shift %>',
                        _plandt: dtpln,
                        _itemno: item,
                        _sitemno: sitem,
                        _side: "L",
                        _rollno: $("#rollno1").text(),
                        _cartno: $("#cartno1").val(),
                        _plylot: $("#lblot1").text(),
                        _plyexp: $("#lbexp1").text(),
                        _plylen: $("#txtlen1").val(),
                        _Plyan1: $("#roll1").val(),
                        _Plyan2: $("#roll2").val(),
                        _Plyan3: $("#roll3").val(),
                        _Plywd1: $("#cart1").val(),
                        _Plywd2: $("#cart2").val(),
                        _Plywd3: $("#cart3").val(),
                        _Plyjn1: $("#join1").val(),
                        _Plyjn2: $("#join2").val(),
                        _Plyjn3: $("#join3").val(),
                        _prddate: $("#prddate").val(),
                        _empname: '<%: User.Identity.Name.ToString() %>'
                    });
                }


                if ((typeof (ply2) != undefined) && $.trim(ply2) != '') {
                    if ((no == 0) || (no == 4) || (no == 5) || (no == 6)) {
                        dataForSubmit.push({
                            _biasno: '<%= Model.First()._biasno %>',
                            _Shift: 1,
                            _plandt: dtpln,
                            _itemno: item,
                            _sitemno: sitem,
                            _side: "R",
                            _rollno: $("#rollno2").text(),
                            _cartno: $("#cartno21").val(),
                            _plylot: $("#lblot2").text(),
                            _plyexp: $("#lbexp2").text(),
                            _plylen: $("#txtlen2").val(),
                            _Plyan1: $("#roll21").val(),
                            _Plyan2: $("#roll22").val(),
                            _Plyan3: $("#roll23").val(),
                            _Plywd1: $("#cart21").val(),
                            _Plywd2: $("#cart22").val(),
                            _Plywd3: $("#cart23").val(),
                            _Plyjn1: $("#join21").val(),
                            _Plyjn2: $("#join22").val(),
                            _Plyjn3: $("#join23").val(),
                            _prddate: $("#prddate").val(),
                            _empname: '<%: User.Identity.Name.ToString() %>'
                        });
                    }
                }
            }
            var getUsersUrl = '<%= Url.Action("SAVE_PLYROLL") %>';
            if (blnR == 'true') callScriptMethod(getUsersUrl, { theData: dataForSubmit }, 'ADD');
            return blnR;
        } // Savedata


        function CheckText(no) {
            var bln = false;
            if (no == undefined) {
                no = 0;
            }
            if ((typeof (ply2) != undefined) && $.trim(ply2) != '') {
                setForPly2(no);
                return;
            } else {
                $("#imgchk21,#imgchk22,#imgchk23").addClass("hide");
            }

            if ((no == 0) || no.between(1, 3)) {
                if (($("#roll1").val() == "") || ($("#cart1").val() == "") || ($("#join1").val() == "")) {
                    $("#imgchk2,#imgchk3").addClass("hide");
                    bln = true;
                } else {
                    DisplayTxt("#roll2,#cart2,#join2");
                    DisableText("#roll1,#cart1,#join1,#roll3,#cart3,#join3");
                    $("#imgchk1").addClass("hide");
                }

                if ((($("#roll2").val() == "") || ($("#cart2").val() == "") || ($("#join2").val() == "")) && bln == false) {
                    DisableText("#roll3,#cart3,#join3");
                    DisplayTxt("#roll2,#cart2,#join2");
                    $("#imgchk2").removeClass("hide");
                    $("#imgchk3,#imgchk1").addClass("hide");
                    bln = true;
                } else if (bln == false) {
                    DisableText("#roll2,#cart2,#join2");
                    DisplayTxt("#roll3,#cart3,#join3");
                    $("#imgchk2").addClass("hide");
                    $("#imgchk3").removeClass("hide");

                }

                if ((($("#roll3").val() == "") || ($("#cart3").val() == "") || ($("#join3").val() == "")) && bln == false) {
                    DisplayTxt("#roll3,#cart3,#join3");
                    $("#imgchk3").removeClass("hide");

                    bln = true;
                } else if (bln == false) {
                    DisableText("#roll3,#cart3,#join3");
                    $("#imgchk3").addClass("hide");

                }

                if ($(".ply1").is("not:disabled")) {
                    $("#print1").addClass("hide");
                }

            }


        } // CheckText



        function setForPly2(no) {

            $("#imgchk1,#imgchk2, #imgchk3").addClass("hide");
            bln = false;
            if ((no == 0) || no.between(4, 6)) {

                if (($("#roll21").val().length <= 0) || ($("#cart21").val().length <= 0) || ($("#join21").val().length <= 0)

                ) {

                    DisplayTxt("#roll21,#cart21,#join21 ,#roll1,#cart1,#join1");
                    DisableText("#roll22,#cart22,#join22,#roll23,#cart23,#join23");
                    $("#imgchk22,#imgchk23").addClass("hide");
                    bln = true;
                } else {
                    DisableText("#roll21,#cart21,#join21 ,#roll1,#cart1,#join1 ");
                    DisplayTxt("#roll2,#cart2,#join2,#roll22,#cart22,#join22");

                    $("#imgchk21").addClass("hide");
                }

                if ((($("#roll22").val() == "") || ($("#cart22").val() == "") || ($("#join22").val() == "")) && bln == false) {
                    DisplayTxt("#roll2,#cart2,#join2,#roll22,#cart22,#join22");
                    DisableText("#roll23,#cart23,#join23,#roll3,#cart3,#join3");
                    $("#imgchk22").removeClass("hide");
                    $("#imgchk23,#imgchk21").addClass("hide");
                    bln = true;
                } else if (bln == false) {
                    DisableText("#roll2,#cart2,#join2,#roll22,#cart22,#join22");
                    DisplayTxt("#roll23,#cart23,#join23,#roll3,#cart3,#join3");
                    $("#imgchk22").addClass("hide");
                    $("#imgchk23").removeClass("hide");

                }

                if ((($("#roll23").val() == "") || ($("#cart23").val() == "") || ($("#join23").val() == "")) && bln == false) {
                    DisplayTxt("#roll23,#cart23,#join23,#roll3,#cart3,#join3");
                    $("#imgchk23").removeClass("hide");

                    bln = true;
                } else if (bln == false) {
                    DisableText("#roll23,#cart23,#join23,#roll3,#cart3,#join3");
                    $("#imgchk23").addClass("hide");

                }
            }
        }



        function callScriptMethod(url, jsonObject, action, callback, async) {

            callback = callback || function () { };
            async = (async == null || async);

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: url,
                data: JSON.stringify(jsonObject),
                dataType: "json",
                async: async,
                success: function (data) {

                    if (data.success != "1") {
                        alert(data.message);
                    } else {
                        if (btnClick.attr("id") == "save") alert(data.message);

                    }
                },
                error: function (xhr, status, error) {
                    var err = xhr.responseText;
                    alert(err.Message);
                }
            });
        }

    });
</script>


</asp:Content>